﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PlutoStudio.Data.MySQL
{
    public class MySQLProvider:Common.ISqlClientProvider
    {
        public System.Data.Common.DbConnection GetConnection(string connectionString)
        {
            return new MySql.Data.MySqlClient.MySqlConnection(connectionString);
        }


        public System.Data.Common.DbParameter GenerateParameter<T>(T item, Common.PropertyItem column)
        {
            var parameterName = string.Format("?{0}", column.ColumnName);
            var parameterValue = column.Property.GetValue(item, null);
            return new MySql.Data.MySqlClient.MySqlParameter(parameterName, parameterValue);
        }

        public System.Data.Common.DbParameter GenerateParameter(Common.PropertyItem column, object value)
        {
            var parameterName = string.Format("?{0}", column.ColumnName);
            return new MySql.Data.MySqlClient.MySqlParameter(parameterName, value);
        }

        public string GenerateIdentifier(string name)
        {
            return string.Format("`{0}`", name);
        }

        public string GenerateParameterName(string name)
        {
            return string.Format("?{0}", name);
        }


    }
}
